package com.ruoyi.project.system.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysServiceOrder;
import com.ruoyi.project.system.service.ISysServiceOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户服务订单Controller
 * 
 * @author jjp
 * @date 2020-04-16
 */
@RestController
@RequestMapping("/system/order")
public class SysServiceOrderController extends BaseController
{
    @Autowired
    private ISysServiceOrderService sysServiceOrderService;

    /**
     * 查询用户服务订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysServiceOrder sysServiceOrder)
    {
        startPage();
        List<SysServiceOrder> list = sysServiceOrderService.selectSysServiceOrderList(sysServiceOrder);
        return getDataTable(list);
    }


    /**
     * 获取用户服务订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(sysServiceOrderService.selectSysServiceOrderById(orderId));
    }

    /**
     * 新增用户服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "用户服务订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysServiceOrder sysServiceOrder)
    {
        return toAjax(sysServiceOrderService.insertSysServiceOrder(sysServiceOrder));
    }

    /**
     * 修改用户服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "用户服务订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysServiceOrder sysServiceOrder)
    {
        sysServiceOrder.setUpdateBy(SecurityUtils.getLoginUser().getUser().getUserName());
        sysServiceOrder.setUpdateTime(new Date());
        return toAjax(sysServiceOrderService.updateSysServiceOrder(sysServiceOrder));
    }

    /**
     * 删除用户服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "用户服务订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(sysServiceOrderService.deleteSysServiceOrderByIds(orderIds));
    }
    /**
     * 审核是否同意用户取消服务订单
     */
    /**
     * 修改用户服务订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:audit')")
    @Log(title = "审核是否取消服务订单", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody SysServiceOrder sysServiceOrder)
    {
        return sysServiceOrderService.audit(sysServiceOrder);
    }

}
